<template>
  <a-modal
    v-model:open="shareVisible"
    :dialogStyle="{ padding: 0 }"
    :width="400"
    :height="200"
    :closeBtn="false"
    :footer="false"
    title="分享实验链接"
  >
    <div class="dialog-main">
      <div class="dialog-content">{{ shareUrl }}</div>
    </div>
    <div class="dialog-footer">
      <div class="dialog-btn" @click="handleCopy">复制链接</div>
    </div>
  </a-modal>
</template>
<script setup>
import { message } from "ant-design-vue";
import { ref, computed } from "vue";
import { useRouter } from "vue-router";
const router = useRouter();
const query = computed(() => router.currentRoute.value.query);
const props = defineProps({
  value: Boolean,
  modelValue: Boolean,
});
const emit = defineEmits(["update:value"]);
const shareUrl = computed(() => {
  return (
    location.href.replace("experiment", "share") +
    "&role=" +
    localStorage.getItem("role")
  );
});

const shareVisible = computed({
  get() {
    return props.value || props.modelValue;
  },
  set(val) {
    emit("update:value", val);
  },
});
const handleCopy = () => {
  navigator.clipboard.writeText(shareUrl.value).then(() => {
    message.success("复制成功");
  });
};
</script>
<style scoped lang="less">
.dialog-header {
  text-align: center;
  padding-bottom: 16px;
  font-family: PingFangSC-Medium;
  font-weight: 500;
  font-size: 18px;
  color: #262626;
}
.dialog-main {
  margin-bottom: 12px;
  box-sizing: border-box;
  .dialog-content {
    text-align: center;
    font-family: PingFangSC-Regular;
    font-weight: 400;
    font-size: 16px;
    color: #262626;
  }
}
.dialog-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  .dialog-btn {
    width: 100px;
    height: 40px;
    background: #2776ff;
    border-radius: 8px;
    font-family: PingFangSC-Regular;
    font-weight: 400;
    font-size: 14px;
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
  }
}
</style>
